package cn.kgc.springbootdemo.util;

import lombok.experimental.UtilityClass;

/**
 * <h3>springbootdemo</h3>
 * <p>字段安全显示工具类</p>
 *
 * @author : DongZeJian
 * @date : 2021-03-27 13:12
 **/
@UtilityClass
public class FieldSecurityInfoUtils {

    /**
     *  字段隐藏为为*
     *
     * @param field
     * @return
     */
    public String hidden(String field){
        if (field.length() == 15) {
            return field.replaceAll("(\\d{4})\\d{7}(\\d{4})", "$1*******$2");
        }

        if (field.length() == 18) {
            return field.replaceAll("(\\d{4})\\d{10}(\\d{4})", "$1**********$2");
        }

        return field.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
    }
}
